// 构建登录弹窗 vue 组件
Vue.component("ly-login",{
    template:`
    <el-dialog title="登录窗口" :visible.sync="showLogin">
      <el-form :model="form">
        <el-form-item label="用户名: ">
          <el-input v-model="form.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码: ">
          <el-input v-model="form.password" type="password" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-link >忘记密码</el-link>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </el-dialog>
    `,
    // vue 组件的data 必须是一个函数
    data(){
        return {
            showLogin : false,
            form : {}
        }
    },
    methods:{
        login(){
            let p = new URLSearchParams();
            for (const name in this.form) {
                p.append(name,this.form[name]);
            }
            axios.post("login",p).then(res=>{
                // 后台返回的是 字符串, 不是json
                this.$alert(res.data);
            })
        }
    }
})



